package com.xyh.web.context;

import com.xyh.web.WebApplicationInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

public abstract class AbstractContextLoaderInitializer implements WebApplicationInitializer {
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		registerContextLoaderListener(servletContext);
	}

	/**
	 * 注册监听器
	 * 根据父容器配置（对应xml版的application.xml）创建了一个容器
	 * 但是这步没有刷新(容器还没有功能)
	 */
	private void registerContextLoaderListener(ServletContext servletContext) {
		ApplicationContext rootAppContext = new ApplicationContext(); //创建一个根容器
		rootAppContext.register("SpringConfig");
		ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
		servletContext.addListener(listener);
	}

}
